package com.coder.gaeblogger.manager;

import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import com.coder.gaeblogger.domain.BlogPost;




public class PostManager extends BlogManager {
	
	private static final Logger log = Logger.getLogger(PostManager.class.getName());
	
	public BlogPost savePost(BlogPost post){		
		PersistenceManager pm = BlogManager.getPMF();
        try {
            pm.makePersistent(post);
        } finally {
            pm.close();
        }
        return post;
		
	}
	
	public BlogPost updatePost(BlogPost post){
		PersistenceManager pm = BlogManager.getPMF();
        try {
            pm.makePersistent(post);
        } finally {
            pm.close();
        }
        return post;
		
	}
	
	@SuppressWarnings("unchecked")
	public List<BlogPost> getPostForHomePage(BlogPost post){
		String query = "select from " + BlogPost.class.getName();
		List<BlogPost> posts;
		PersistenceManager pm = BlogManager.getPMF();
        try {
            
            posts = (List<BlogPost>) pm.newQuery(query).execute();
        } finally {
            pm.close();
        }
		return posts;
		
	}
	
	

}
